package com.stations.controller;

import com.github.pagehelper.PageInfo;
import com.stations.common.constant.ControllerConstant;
import com.stations.common.web.base.BaseController;
import com.stations.common.web.domain.request.PageDomain;
import com.stations.common.web.domain.response.Result;
import com.stations.common.web.domain.response.module.ResultTable;
import com.stations.domain.TTransmitterException;
import com.stations.domain.TTransmitterTask;
import com.stations.domain.dtree.DTreeResponse;
import com.stations.service.TrasmiterExceptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Describe: 发射机控制器
 * Author: Ljy
 * CreateTime: 2019/10/23
 */
@RestController
@Api(tags = {"发射机告警管理"})
@RequestMapping(ControllerConstant.API_SYSTEM_PREFIX + "transmitterexception")
public class TransmiterExceptionController extends BaseController {

    /**
     * Describe: 基础路径
     */
    private static String MODULE_PATH = "system/transmitterexception/";

    @Resource
    private TrasmiterExceptionService trasmiterExceptionService;

    /**
     * Describe: 获取发射机告警列表
     * Param ModelAndView
     * Return 发射机告警
     */
    @GetMapping(value = "/getExceptions")
    @ApiOperation(value = "获取台站列表")
    @PreAuthorize("hasPermission('/system/transmitterexception/getExceptions','sys:transmitterexception:getExceptions')")
    public Result getExceptions(HttpServletRequest request) {
        List<TTransmitterException> lisTTransmitterException = trasmiterExceptionService.getExceptions();
        return Result.success(lisTTransmitterException);
    }
    /**
     * 分页查询发射机列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/system/transmitterexception/data','sys:transmitterexception:data')")
    public ResultTable list(@ModelAttribute TTransmitterException tTransmitterException, PageDomain pageDomain) {
        PageInfo<TTransmitterException> pageInfo = trasmiterExceptionService.selectTTransmitterExceptionPage(tTransmitterException, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }
    /**
     * Describe: 获取发射机实时告警列表
     * Param ModelAndView
     * Return 获取发射机实时告警列表
     */
    @GetMapping(value = "/getExceptionsRedis")
    @ApiOperation(value = "获取发射机实时告警列表")
    @PreAuthorize("hasPermission('/system/transmitterexception/getExceptionsRedis','sys:transmitterexception:getExceptionsRedis')")
    public Result getExceptionsRedis(@RequestParam(value="stationCode") String stationCode,@RequestParam(value="transCode") String transCode) {
        List<TTransmitterException> lisTTransmitterException = trasmiterExceptionService.getExceptionsRedis(stationCode,transCode);
        return Result.success(lisTTransmitterException);
    }
}
